package de.hsb.ai.domain;

import jade.content.Concept;
import jade.core.AID;

import java.util.List;

public class GameInfo implements Concept {
	
	private static final long serialVersionUID = -8028558756608327150L;
	
	private jade.util.leap.ArrayList players = new jade.util.leap.ArrayList(ScotlandJadeVocabulary.MAX_PLAYERS);

	/**
	 * Sets the list of players to the specified one.
	 * @param players
	 */
	public void setPlayers(List<AID> players) {
		if (players.size() > ScotlandJadeOntology.MAX_PLAYERS)
			throw new IllegalArgumentException("Not more than " + ScotlandJadeOntology.MAX_PLAYERS + " players are permitted");
		this.players.fromList(players);
	}

	/**
	 * Returns the list of players.
	 * @return a list of {@link AID AIDs} 
	 */
	@SuppressWarnings("unchecked")
	public List<AID> getPlayers() {
		return players.toList();
	}
	
	/**
	 * Adds as single (player) AID to the list.
	 * Used internally by JADE.
	 * @param player
	 */
	public void addPlayers(AID player) {
		players.add(player);
	}
	
	/**
	 * Sets player list.
	 * Used internally by JADE. Use {@link #setPlayers(List)} instead.
	 * @see #setPlayers(List)
	 * @param players
	 */
	public void setAllPlayers(jade.util.leap.ArrayList players) {
		this.players = players;
	}
	
	/**
	 * Returns player list.
	 * Used internally by JADE. Use {@link #getPlayers()} instead.
	 * @see #getPlayers()
	 * @return
	 */
	public jade.util.leap.ArrayList getAllPlayers() {
		return players;
	}
	
	@Override
	public int hashCode() {
		return getPlayers().hashCode();
	}
	
	@Override
	public boolean equals(Object obj) {
		if (obj == this) return true;
		if (obj instanceof GameInfo) {
			return obj.hashCode() == this.hashCode();
		}
		return false;
	}
	
}
